package com.acwing.partition8;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/1/15 22:48
 */
public class AC785快速排序 {

    private static final int N = 100010;
    private static int n = 0;
    private static int[] nums = new int[N];

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        String[] s = reader.readLine().split("\\s+");
        for (int i = 0; i < n; i++) nums[i] = Integer.parseInt(s[i]);
        quickSort(0, n - 1);
        for (int i = 0; i < n; i++) writer.write(nums[i] + " ");
        writer.flush();
    }

    private static void quickSort(int left, int right) {
        if (left >= right) return;
        int i = left - 1, j = right + 1, m = nums[(left + right) >>> 1];
        while (i < j) {
            do i++; while (nums[i] < m);
            do j--; while (nums[j] > m);
            if (i < j) {
                int t = nums[i];
                nums[i] = nums[j];
                nums[j] = t;
            }
        }
        quickSort(left, j);
        quickSort(j + 1, right);
    }
}
